<template>
  <div>
    <van-sticky>
      <van-nav-bar
        title="预约记录"
        left-text="返回"
        left-arrow
        @click-left="onClickLeft"
      />
    </van-sticky>
    <!-- 表格 -->
    <!-- <vxe-table
      v-if="recordArr && recordArr.length"
      border="inner"
      size="mini"
      :data="recordArr.reverse()"
    >
      <vxe-column type="seq" width="40"></vxe-column>
      <vxe-column
        :field="'appointmentReceiveCode'"
        :title="'预约编号'"
        width="130"
      />
      <vxe-column :field="'createAt'" :title="'时间'" />
      <vxe-column :field="'status'" :title="'预约状态'" width="80" />
    </vxe-table> -->
    <div v-if="recordArr && recordArr.length">
      <van-pull-refresh
        v-model="refreshing"
        loosing-text="下拉刷新"
        @refresh="onRefresh"
      >
        <van-list
          v-model:loading="loading"
          :finished="finished"
          finished-text="没有更多了"
          offset="20"
          @load="onLoad"
        >
          <div class="main">
            <van-row class="row row-header" justify="center">
              <van-col :span="2">
                <div class="header">
                  <span>#</span>
                </div>
              </van-col>
              <van-col :span="9">
                <div class="header">
                  <span>预约编号</span>
                </div>
              </van-col>
              <van-col :span="9">
                <div class="header">
                  <span>时间</span>
                </div>
              </van-col>
              <van-col :span="4">
                <div class="header">
                  <span>预约状态</span>
                </div>
              </van-col>
            </van-row>
            <van-row
              v-for="(item, index) in recordArr"
              :key="item"
              class="row"
              justify="center"
            >
              <van-col :span="2">
                <div class="column">
                  <span>{{ 1 + index }}</span>
                </div>
              </van-col>
              <van-col :span="9">
                <div class="column">
                  <span>{{ item.appointmentReceiveCode }}</span>
                </div>
              </van-col>
              <van-col :span="9">
                <div class="column">
                  <span>{{ item.createAt }}</span>
                </div>
              </van-col>
              <van-col :span="4">
                <div class="column">
                  <span>{{ item.status }}</span>
                </div>
              </van-col>
            </van-row>
          </div>
        </van-list>
      </van-pull-refresh>
    </div>

    <div v-else style="margin-top: 10px" class="noneImg">
      <img class="none" src="../../../../assets/icon/none.png" alt="" />
      <div class="van-list__finished-text">暂无记录</div>
    </div>
  </div>
</template>
<script lang="ts">
import axios from '/@/api/axios'
import { defineComponent, ref } from 'vue'

export default defineComponent({
  components: {},
  setup() {
    const recordArr: any = ref([])
    let current = ref(1)
    const loading = ref(false)
    const finished = ref(false)
    const refreshing = ref(false)

    const onLoad = async () => {
      if (refreshing.value) {
        refreshing.value = false
      }
      await loadReserveRecords()
    }
    // 获取预约记录
    async function loadReserveRecords() {
      let { data } = await axios({
        url: `/api/blade-appointment/appointment/receive/findReceiveList`,
        method: 'get',
        params: {
          current: current.value,
          size: 10,
        },
      })
      //请求后页数+1，以备下次请求
      current.value++
      data = (data && data.data) || {}
      data.records.map((item: any) => {
        if (item.status == 1) {
          item.status = '正常'
        } else if (item.status == 0) {
          item.status = '已完成'
        } else {
          item.status = '已完成'
        }
        recordArr.value.push(item)
        return item
      })

      loading.value = false
      if (recordArr.value.length >= data.total) {
        finished.value = true
      }
    }

    const onRefresh = () => {
      finished.value = false
      loading.value = true
      onLoad()
    }
    onRefresh()

    return {
      recordArr,
      onClickLeft() {
        history.back()
      },
      current,
      loading,
      finished,
      refreshing,
      onRefresh,
      onLoad,
    }
  },
})
</script>

<style lang="less" scoped>
.noneImg {
  text-align: center;
  .none {
    width: 110px;
    margin-top: 23vh;
  }
}

.row {
  margin-top: 8px;
  padding-top: 8px;
  color: #606266;
  border-top: 1px solid #e8eef5;

  .header {
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 12px;
    font-weight: bold;
  }

  .column {
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 12px;
  }
}

.row-header {
  margin-top: 1px;
  padding-top: 5px;
}
</style>
